package 笔试.美团;

import java.util.Scanner;

//并查集
public class Demo04 {
    private static int x = 10001;
    private static int[] next = new int[x], count = new int[x];
    public static void main(String[] args) {
        //BufferedWriter w = new BufferedWriter(new OutputStreamWriter(System.out));
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int[][] tmp = new int[n/2][2];
        for (int i = 0; i < n / 2; i++) tmp[i][0] = s.nextInt();
        for (int i = 0; i < n / 2; i++) tmp[i][1] = s.nextInt();
        for (int i = 0; i < next.length; i++) {
            next[i] = i;
            count[i] = 1;
        }
        for (int i = 0; i < n / 2; i++) {
            if (tmp[i][0]!=tmp[i][1]){
                union(tmp[i][0],tmp[i][1]);
            }
        }
        int res = 0;
        for (int i = 0; i < x; i++) {
            if (i==find(i)) res += (count[i]-1);
        }
        System.out.println(res);
    }
    private static void union(int i, int j){
        int ii = find(i);
        int jj = find(j);
        if (ii==jj) return;
        if (count[ii]>count[jj]){
            next[jj] = ii;
            count[ii] += count[jj];
        }else{
            next[ii] = jj;
            count[jj] += count[ii];
        }
    }
    private static int find(int i){
        while(next[i]!=i) i = next[i];
        return i;
    }
}